<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        // 找到数组中每个字母出现的次数["c", "a", "z", "a", "a","b"]
        var arr = ["c", "a", "z", "a", "a", "b"];
        function counter(arr) {
            var obj = {};
            for (var i = 0; i < arr.length; i++) {

                // 取数组元素，为字符串
                var attr = arr[i]
                // 判断在obj中是否已经存在 该元素  对应的  属性
                if (!obj[attr]) {
                    // 首次出现
                    obj[attr] = 1;
                } else {
                    obj[attr]++;
                }
            }
            return obj;
        }

        console.log(counter(arr));
    </script>
</body>
</html>